import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-10-30
 * Time: 8:31
 */
public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++){
            a[i] = in.nextInt();
        }
        Queue<Integer> maxQue = new ArrayDeque<>();
        for (int i = 0; i < n - k + 1; i++){
            int j = 0;
            int max = a[i + j];
            int min = a[i + j];
            for (j = 1; j < k; j++){
                max = Math.max(max,a[i + j]);
                min = Math.min(min, a[i + j]);
            }
            maxQue.offer(max);
            System.out.print(min + " ");
        }
        System.out.println();
        while (!maxQue.isEmpty())
            System.out.print(maxQue.poll() + " ");
    }
}
